<template>
  <div class="datalist">
    <el-row class="row" :gutter="4" style="height: 100%">
      <el-col :span="4" class="col" v-if="flowTree">
        <el-tree class="tree" :data="flowTree" :props="{ children: 'sons', label: 'label' }" :default-expand-all="true"
          :expand-on-click-node="false" @node-click="treeClick" highlight-current></el-tree>
      </el-col>
      <el-col :span="20" class="col" style="height: 100%">
        <div class="datalist">
          <div class="header">
            <span style="margin-left: 20px">关键字</span>
            <el-input placeholder="请输入关键字" v-model="logReq.keyword" style="width: 200px; margin-left: 10px"
              clearable></el-input>
            <el-button type="primary" style="margin-left: 20px" size="small" @click="
              logReq.pageIndex = 1
            getCaseLogs()
              ">
              关键字搜索
            </el-button>
          </div>
          <div class="content">
            <div style="flex: auto">
              <el-table height="calc(100% - 50px)" :data="logRes.Items" stripe border highlight-current-row>
                <el-table-column type="index" width="40"></el-table-column>
                <el-table-column label="类型" width="100">
                  <template slot-scope="scope">
                    {{
                      scope.row.FLOW_Name ? scope.row.FLOW_Name : '旧系统迁移'
                    }}
                  </template>
                </el-table-column>
                <el-table-column label="日志">
                  <template slot-scope="scope">
                    {{ scope.row.CLG_DisplayName }}
                  </template>
                </el-table-column>
                <el-table-column label="作业时间" width="220">
                  <template slot-scope="scope">
                    {{ scope.row.CLG_StartTime | formatDate }}~{{
                      scope.row.CLG_EndTime | formatDate
                    }}
                  </template>
                </el-table-column>
                <el-table-column label="内容">
                  <template slot-scope="scope">
                    {{ scope.row.CLG_Content }}
                  </template>
                </el-table-column>
                <el-table-column label="录入时间" width="160">
                  <template slot-scope="scope">
                    {{ scope.row.CLG_CreateTime | formatDate }}
                  </template>
                </el-table-column>
                <el-table-column fixed="right" label="操作" width="160px">
                  <template slot-scope="scope">
                    <el-button type="text" size="small" v-if="scope.row.CLG_FormID"
                      @click="toForm(scope.row.CLG_FormID)" icon="el-icon-search">
                      流程
                    </el-button>
                    <el-button type="text" size="small" v-else @click="toOldForm(scope.row.CLG_ID)"
                      icon="el-icon-search">
                      旧系统流程
                    </el-button>
                    <el-button type="text" size="small" icon="el-icon-delete" @click="deleteLog(scope.row.CLG_ID)">
                      删除
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div class="pagination">
              <el-pagination layout="total,prev,pager,next,sizes" style="float: right" background
                :current-page.sync="logReq.pageIndex" :total="logRes.Total" :page-size="logReq.pageSize"
                :page-sizes="[10, 15, 20]" @size-change="
                  (val) => {
                    logReq.pageSize = val
                    getCaseLogs()
                  }
                " @current-change="getCaseLogs()"></el-pagination>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import { getCaseLogs, getFlowTrees, deleteLog } from '@/api/core/caseLog'
export default {
  props: ['caseId'],
  data: function () {
    return {
      flowTree: null,
      curFlow: null,
      logReq: {
        caseId: null,
        keyword: '',
        pageIndex: 1,
        pageSize: 10,
      },
      logRes: {
        Items: [],
        Total: 0,
      },
    }
  },
  methods: {
    toForm(formId) {
      this.$router.push({
        name: 'formInfoPage',
        query: { formId },
      })
    },
    toOldForm(formId) {
      window.open('http://111.230.247.78:8443/#/myWorkflow/handleAssessLog/' + formId, '_blank')
    },
    treeClick(item) {
      this.curFlow = item.tag
      this.getCaseLogs()
    },
    getFlowTrees() {
      getFlowTrees().then(({ data }) => {
        this.flowTree = data
        this.getCaseLogs()
      })
    },
    getCaseLogs() {
      this.logReq.caseId = this.caseId
      getCaseLogs(this.logReq).then(({ data }) => {
        this.logRes = data
      })
    },
    deleteLog(id) {
      this.$confirm(`是否删除该日志`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        deleteLog(id).then(() => {
          this.getCaseLogs()
        })
      })
    },
  },
  created: function () {
    if (!this.caseId) {
      return
    }
    this.getFlowTrees()
  },
}
</script>
<style>
.el-drawer.rtl {
  overflow: scroll;
}
</style>
<style scoped>
.row {
  height: 100%;
}

.col {
  height: 100%;
}

.col .col_header {
  background: #d9e5fe;
  padding-left: 10px;
  height: 60px;
  display: flex;
  flex-direction: row;
  align-items: center;
}

.col .col_content {
  height: calc(100% - 80px);
  background: white;
  display: flex;
  flex-direction: column;
}

.col .col_content .tree {
  height: 100%;
  width: 100%;
  background: white;
  overflow: auto;
}
</style>
